package com.hxl.demo.controller;

import com.hxl.demo.entity.TrainingContents;
import com.hxl.demo.entity.TrainingRecord;
import com.hxl.demo.entity.User;
import com.hxl.demo.mapper.TrainingContentsMapper;
import com.hxl.demo.mapper.TrainingRecordMapper;
import com.hxl.demo.mapper.UserMapper;
import com.hxl.demo.service.Impl.TrainingRecodeServiceImpl;
import com.hxl.demo.tools.Common;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 数据更新
 */
@RestController
@RequestMapping("/admin")
public class UserController {
    @Resource
    private UserMapper userMapper;

    @Resource
    private TrainingRecordMapper trainingRecordMapper;

    @Resource
    private TrainingRecord trainingRecord;

    @Resource
    private TrainingContentsMapper trainingContentsMapper;

    @Resource
    private TrainingRecodeServiceImpl trainingRecodeServiceImpl;


    @RequestMapping("/updateUser")
    public void updateUser(){
        List<User> userList=userMapper.updateList();
        if(userList!=null && userList.size()>0){
            for (User user:userList){
                User user1=new User();
                user1.setId(user.getId());
                String password= DigestUtils.md5DigestAsHex(user.getUsername().getBytes());
                user1.setPassword(password);
                userMapper.updatePassword(user1);
            }
        }

    }
//    @RequestMapping("/trainingRecordAllList")
//    public void updateTrainingRecord(){
//        List<TrainingRecord> trainingRecordList =trainingRecordMapper.trainingRecordAllList();
//        if(trainingRecordList!=null && trainingRecordList.size()>0){
//            for(TrainingRecord trainingRecord:trainingRecordList){
//                TrainingRecord trainingRecordNew=new TrainingRecord();
//                if(trainingRecordNew.getContentId()!=null){
//                    TrainingContents  trainingContents= trainingContentsMapper.getTrainingContentsDetail(trainingRecordNew.getContentId());
////                    List<Map<String,Object>> trainingRecordCount = trainingRecodeServiceImpl.getRecodeByCount(useId, contentId);
//                    if(trainingContents!=null){
//                        Integer times=trainingContents.getTrainingTime();
//                        trainingRecordNew.setId(trainingRecordNew.getContentId());
//                        trainingRecordNew.setTrainingTime(trainingContents.getTrainingTime());
////                        trainingRecordNew.setEndTime();
//
//                    }
//
//
//                }
//
//            }
//        }
//    }
//    @RequestMapping("/trainingRecordAllList")
//    public void updateTrainingRecord() {
//        List<TrainingRecord> trainingRecordList =trainingRecordMapper.trainingRecordAllList();
//
//        if(trainingRecordList!=null && trainingRecordList.size()>0){
//            for (TrainingRecord trainingRecord:trainingRecordList){
//
//            }
//        }
//
//    List<Map<String,Object>> trainingRecord = trainingRecodeServiceImpl.getRecodeById(useId, contentId);
//    List<Map<String,Object>> trainingRecordCount = trainingRecodeServiceImpl.getRecodeByCount(useId, contentId);
//
//    Integer cumulativeTime=0;
//
//
//            if(trainingRecord==null){
//        return Common.returnJsonFail("操作失败",400);
//    }
////            总学习时长
//            if(trainingRecordCount!=null){
//        cumulativeTime= (int) trainingRecordCount.get(0).get("cumulative_time");
//    }
//
//
//    Integer count=trainingTime+cumulativeTime;
//
//    Integer id= trainingRecodeServiceImpl.endStudy(Integer.valueOf(trainingRecord.get(0).get("id").toString()),date,trainingTime,count);
//    }
}
